import request from "@/utils/request.js";

const Api = {
    create: "/v1/system/role",
    export: "/v1/system/role/export",
    delete: "/v1/system/role/",
    batchDelete: "/v1/system/role/batch/del",
    update: "/v1/system/role/",
    updateRolePermission: "/v1/system/role/permission/",
    getList: "/v1/system/role",
    getListAll: "/v1/system/role/list/all",
    getRoleMenu: "/v1/system/roleMenu/",
    getRoleMenuItem: "/v1/system/roleMenuItem/",
    getObj: "/v1/system/role/",
}

/**
 * 创建角色
 */
export const create_role = (data) => {
    return request({
        url: Api.create,
        method: "POST",
        data,
    });
};

/**
 * 导入角色
 */
export const export_role = (data) => {
    return request({
        url: Api.export,
        method: "POST",
        headers: {
            "Content-Type": "multipart/form-data",
        },
        data,
    });
};

/**
 * 删除字典
 */
export const delete_role = (id) => {
    return request({
        url: Api.delete + id,
        method: "DELETE",
    });
};

/**
 * 批量删除字典
 */
export const batch_delete_role = (ids) => {
    return request({
        url: Api.batchDelete,
        method: "DELETE",
        data: ids,
    });
};

/**
 * 更新角色
 */
export const update_role = (id, data) => {
    return request({
        url: Api.update + id,
        method: "PUT",
        data,
    });
};

/**
 * 更新角色菜单权限
 */
export const update_role_permission = (id, data) => {
    return request({
        url: Api.updateRolePermission + id,
        method: "PUT",
        data,
    });
};

/**
 * 获取分页角色列表
 */
export const get_role_list = (params) => {
    return request({
        url: Api.getList,
        method: "GET",
        params,
    });
};

/**
 * 获取角色全部列表
 */
export const get_role_list_all = (params) => {
    return request({
        url: Api.getListAll,
        method: "GET",
        params,
    });
};

/**
 * 获取角色菜单列表
 */
export const get_role_menu = (id) => {
    return request({
        url: Api.getRoleMenu + id,
        method: "GET",
    });
};

/**
 * 获取角色菜单权限列表
 */
export const get_role_menu_item = (id) => {
    return request({
        url: Api.getRoleMenuItem + id,
        method: "GET",
    });
};

/**
 * 获取角色
 */
export const get_role_obj = (id) => {
    return request({
        url: Api.getObj + id,
        method: "GET",
    });
};